package com.sn.system.common.action;

import java.io.Serializable;
import java.util.List;

import com.sn.system.common.constants.CommonConstants;
import com.sn.system.common.service.ICommonService;
import com.sn.system.common.utils.ReflectionHelper;

import org.apache.struts2.interceptor.validation.SkipValidation;

import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{
	
	protected ICommonService commonService;
	
	protected String refrenceId;
	
	protected List refrenceList;
	
	protected Object obj;
	
	protected Object objId;
	
	protected String objClass;
	
	public String check() throws Exception {
		
		return SUCCESS;
	}

	public String reference() throws Exception {
		setRefrenceList(this.commonService.selectAll(CommonConstants.POJO_CLASSES.get(refrenceId)));
		return SUCCESS;
	}
	
	public String findObj() throws Exception{
		dofindObj();
		return SUCCESS;
	}
	
	protected boolean dofindObj()
	{
		if(objId instanceof String[] && ((String[])objId)!=null &&((String[])objId).length>0 )
		{
			objId=((String[])objId)[0];
		}
		this.obj=commonService.selectObject(CommonConstants.POJO_CLASSES.get(objClass), (Serializable) objId);
		
		if(this.obj!=null)
		{
			return true;
		}
		
		return false;
	}
	
	public void setCommonService(ICommonService commonService) {
		this.commonService = commonService;
	}

	public String getRefrenceId() {
		return refrenceId;
	}

	public void setRefrenceId(String refrenceId) {
		this.refrenceId = refrenceId;
	}

	public List getRefrenceList() {
		return refrenceList;
	}

	public void setRefrenceList(List refrenceList) {
		this.refrenceList = refrenceList;
	}

	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	public Object getObjId() {
		return objId;
	}

	public void setObjId(Object objId) {
		this.objId = objId;
	}

	public String getObjClass() {
		return objClass;
	}

	public void setObjClass(String objClass) {
		this.objClass = objClass;
	}
	
	
}
